import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import ElementPlus from "unplugin-element-plus/vite";
import Icons from 'unplugin-icons/vite'
import { FileSystemIconLoader } from 'unplugin-icons/loaders'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'


// https://vitejs.dev/config/
export default defineConfig({
  define: { "process.env": {} },
  server: {
    // host: '0.0.0.0'
    port: 3017,
    proxy: {
      '/api':  {
        target: '192.168.0.104:9007',
        // target: 'https://ceres.zkthink.com/api',
        // target: 'https://ceresdev.zkthink.com/api',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      }
    },
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
    },
    extensions: [".js", ".ts", '.vue'], // 使用路径别名时想要省略的后缀名，可以自己 增减
  },
  css: {
    preprocessorOptions: {
      scss: {
        charset: false,
        // 使用element做scss变量总入口文件
        additionalData: `
          @use "@/styles/element/index.scss" as *;
        `,
      },
    },
  },
  build: {
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      }
    },
    minify:'terser',
    // Turning off brotliSize display can slightly reduce packaging time
    brotliSize: false,
    chunkSizeWarningLimit: 2000,
    /**
     * v8 2019.10.8 https://v8.dev/features/top-level-await
     * chrome https://chromestatus.com/feature/5767881411264512
     * firefox https://spidermonkey.dev/blog/2021/04/05/top-level-await-ships.html
     * safari https://webkit.org/blog/11989/new-webkit-features-in-safari-15/
     */
    target:['edge89','chrome89','firefox89','safari15']
  },
  plugins: [
    vue(),
    // eslint
    // element 配置
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver({
        importStyle: 'sass'
      })],
      directoryAsNamespace: true
    }),
    ElementPlus({
      useSource: true
    }),
    createSvgIconsPlugin({
      // Specify the icon folder to be cached
      iconDirs: [
        resolve(process.cwd(), 'src/assets/svg'),
      ],
      // Specify symbolId format
      symbolId: 'icon-[dir]-[name]',
    }),
    // Icons({
    //   compiler: "vue3",
    //   // defaultStyle: 'fill: currentColor',
    //   customCollections: {
    //     // svg: 'src/assets/svg'
    //     svg: FileSystemIconLoader(
    //       'src/assets/svg',
    //       async svg => {
    //         // console.log('FileSystemIconLoader svg', svg)
    //         return svg
    //       }
    //     ),
    //   },
    //   iconCustomizer(collection, icon, props) {
    //     if (collection) {
    //       props.fill = 'currentColor'
    //       props.width = '1em'
    //       props.height = '1em'
    //     }
    //   },
    // }),
  ],
});
